Let's check out the platform we're currently running on

In [ ]:
import platform
print(platform.uname())
uname_result(system='Linux', node='01a8cbf55cbe', release='5.10.104-linuxkit', version='#1 SMP Thu Mar 17 17:08:06 UTC 2022', machine='armv7l')

Hopefully that shows armv7l :) Time to use this code. The example has a simple add() function we can use to check that the package can be found and used.

In [ ]:
import example as m
print(m.add(1, 2))
3

Incredible.

In [ ]:
# print(m.add_quad([0, 1, 2, 3], [-1, -2, 4, 7]))
In [ ]:
from plotly.subplots import make_subplots
import plotly.graph_objects as go
# import numpy as np

def plot(x, y):
    fig = make_subplots(rows=1, cols=1)
    fig.add_trace(go.Scatter(x=x, y=y), row=1, col=1)
    fig.update_yaxes(title_text='y', row=1, col=1)
    fig.update_xaxes(title_text='n', row=1, col=1)
    fig.show()

Time to use the Magic Circle to generate a sine wave.

In [ ]:
osc = m.MagicCircle()
sample_rate = 1_000.0 
osc.set_freq(sample_rate / 256, sample_rate)
x = [float(i) for i in range(0, int(sample_rate))]
y = [osc.advance() for i in x]
plot(x, y)

Here we generate 4 seconds of audio and add a player into this notebook.

In [ ]:
from IPython.display import Audio

sample_rate = 44_100.
osc.reset()
osc.set_freq(440.0, sample_rate)
Audio([osc.advance() for i in range(0, 4 * int(sample_rate))], rate=sample_rate)
Out[ ]:
Your browser does not support the audio element.

For those who don't have perfect pitch, it might be useful to check out the actual frequency of this sine wave

In [ ]:
sample_rate=1_000.
osc.reset()
osc.set_freq(10.0, sample_rate)
# Y = np.fft.fft([osc.advance() for i in range(0, 4 * int(sample_rate))])
# N = len(Y)
# n = np.arange(N)
# T = N / sample_rate
# freq = n / T 
# plot(freq, Y)